
import { getSessionItem,setSessionItem } from 'utils/sessionStorage';
import {

  ACTION_SET_PHONE,
  ACTION_SET_STEP,
  ACTION_SET_HISTORY_STEP,
  ACTION_SET_DEFAULT_SELECTED_KEYS,
  ACTION_SET_DEFAULT_OPEN_KEYS
} from './actions';
import { Iaction } from '../Pages/VerifyAccount/verify';
import { DEFAULT_SELECTED_KEYS, DEFAULT_OPEN_KEYS } from 'Common/common';

console.log(sessionStorage.getItem(DEFAULT_OPEN_KEYS))
export default {
  phone(state: string = '', action: Iaction) {
    const { type, payload } = action;
    switch (type) {
      case ACTION_SET_PHONE:
        return payload
      default:
    }
    return state
  },
  step(state: string = '1', action: Iaction) {
    const { type, payload } = action;
    switch (type) {
      case ACTION_SET_STEP:
        return payload
      default:
    }
    return state
  },
  historyStep(state: string = '1', action: Iaction) {
    const { type, payload } = action;
    switch (type) {
      case ACTION_SET_HISTORY_STEP:
        return payload
      default:
    }
    return state
  },
  defaultSelectedKeys(state: string = getSessionItem(DEFAULT_SELECTED_KEYS) || "['1']", action: Iaction) {
    const { type, payload } = action;
    switch (type) {
      case ACTION_SET_DEFAULT_SELECTED_KEYS:
        setSessionItem(DEFAULT_SELECTED_KEYS, payload);
        return payload
      default:
        setSessionItem(DEFAULT_SELECTED_KEYS, state);
    }
    return state
  },
  defaultOpenKeys(state: Array<string> = JSON.parse(getSessionItem(DEFAULT_OPEN_KEYS)), action: Iaction) {
    const { type, payload } = action;
    console.log(type, payload)
    switch (type) {
      case ACTION_SET_DEFAULT_OPEN_KEYS:
        setSessionItem(DEFAULT_OPEN_KEYS, JSON.stringify(payload));
        return payload
      default:
        setSessionItem(DEFAULT_OPEN_KEYS, JSON.stringify(state));
        console.log(action);
    }
    return state
  }
}